﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using ConnectToDatabase;

namespace QLGiayDep.Forms
{
    /// <summary>
    /// Interaction logic for WinNhanVien.xaml
    /// </summary>
    public partial class WinThemNhanVien : Window
    {
        
        private SelectDB selectDB;
        private SetID setID;
        private InsertDB insertDB;
        private string URL;
    
        
        public WinThemNhanVien()
        {
            InitializeComponent();
          
        }

        public WinThemNhanVien(string _URL)
        {
            InitializeComponent();
            URL = _URL;
            setID = (SetID)Activator.GetObject(typeof(SetID), URL + "SETID_OBJECT");
            insertDB = (InsertDB)Activator.GetObject(typeof(InsertDB), URL + "INSERTDB_OBJECT");
            selectDB = (SelectDB)Activator.GetObject(typeof(SelectDB), URL + "SELECTDB_OBJECT");
            txtMaNV.Text = setID.GenerateMaNV();
            for (int i = 0; i < selectDB.SelectAllDSLoaiNV(1).Count; i++)
            {
                cmbLoaiNV.Items.Add(selectDB.SelectAllDSLoaiNV(1)[i].TenLoaiNhanVien.ToString());
            }
        }
       

        private void bntThemNV_Click(object sender, RoutedEventArgs e)
        {
            int kt;
            string temp;
            string MaLoaiNV;
            temp = cmbLoaiNV.SelectedItem.ToString();
            MaLoaiNV = selectDB.GetMaLoaiNV(temp);
            kt = insertDB.InsertNhanVien(txtMaNV.Text, MaLoaiNV, txtTenNV.Text, 1);
            if (kt == -1)
                MessageBox.Show("Thêm Nhân Viên Thất Bại", "Lỗi");
            else
            {
                MessageBox.Show("Thêm Nhân Viên Thành Công", "Thông Báo");
                txtMaNV.Text = setID.GenerateMaNV();
                txtTenNV.Clear();
            }
        }

        private void bntThoatNV_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }
    }
}
